#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const int N = 65;

int n;
char s1[N], s2[N], s3[N], s4[N];
char str[3];

string date[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int main()
{
	cin >> s1 >> s2 >> s3 >> s4;
	string s;
	
	int cnt = 0;
	// int l1 = strlen(s1), l2 = strlen(s3);
	int i = 0;
	while(i < strlen(s1) && i < strlen(s2))
	{
		if(s1[i] == s2[i] && s1[i] >= 'A' && s1[i] <= 'G' )
		{
			str[cnt] = s1[i];
			cnt ++;
			break;
		}
		i ++;
	}
	i = i + 1;
	while(i < strlen(s1) && i < strlen(s2))
	{
		if(s1[i] == s2[i] && ((s1[i] >= 'A' && s1[i] <= 'N') || isdigit(s1[i])))
		{
			str[cnt] = s1[i];
			cnt ++;
			break;
		} 
		i ++;
	}
	int m = 0, j = 0;
	while(j < strlen(s3) && j < strlen(s4))
	{
		if(s3[j] == s4[j] && isalpha(s3[j]))
		{
			m = j;
			break;
		}
		j ++;
	}
	s = date[(int)(str[0] - 'A')] + " ";
	cout << s;
	int h = 0;
	if(str[1] >= 'A' && str[1] <= 'N') h = 10 + (int)(str[1] - 'A');
	else h = (int)(str[1] - '0');
 	printf("%02d:%02d\n", h, m);
	return 0;
}